package com.xml.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.xml.domain.Admin;
import com.xml.domain.Reader;
import com.xml.utils.HibernateUtils;

public class LoginDaoImpl implements LoginDao {

	@Override
	public List<Admin> get_Admin() {
		Session session = HibernateUtils.getSession();
		Transaction transaction = session.beginTransaction();
		
		List<Admin> list= session.createQuery("from Admin").list();
		
		transaction.commit();
		session.close();
		return list;
	}

	@Override
	public boolean checkReader(String userName, String password) {
		Session session = HibernateUtils.getSession();
		Transaction transaction = session.beginTransaction();
		List<Reader> list= session.createQuery("from Reader").list();
		transaction.commit();
		session.close();
		for(Reader reader : list){
			if(reader.getReaderId().equals(userName)&&reader.getPassword().equals(password))
				return true;
		}
		
		return false;
	}

	@Override
	public boolean checkAdmin(String userName, String password) {
		Session session = HibernateUtils.getSession();
		Transaction transaction = session.beginTransaction();
		List<Admin> list= session.createQuery("from Admin").list();
		transaction.commit();
		session.close();
		for(Admin admin : list){
			if(admin.getAdminId().equals(userName)&&admin.getAdminPassword().equals(password))
				return true;
		}
		
		return false;
	}

}
